# -*- coding: utf-8 -*-
'''
Created on 2018.04.25
@author: wuyou
'''

import requests
import json

class Interface():
	#删除实时缓存数据
	def del_realtime_cache(self,url,data):
		try:
			headers = {'Content-Type': 'application/json;charset=UTF-8'}
			result = requests.post(url,data=json.dumps(data), headers=headers)
			print("删除缓存结果: " + str(result))
		except Exception as error:
			print(url + " : Add realtime cache failed! ")
			print("删除缓存结果: " + str(error))
			result = 'false'
		return result

	#推实时的缓存接口
	def add_realtime_cache(self,url,data):
		try:
			headers = {'Content-Type': 'application/json;charset=UTF-8'}
			result = requests.post(url,data=json.dumps(data), headers=headers)
			print("推送缓存结果: " + str(result))
		except Exception as error:
			print(url + " : Add realtime cache failed! ")
			print("推送缓存结果: " + str(error))
			result = 'false'
		return result

	#实时反欺诈接口
	def inf_realtime(self,url,data):
		try:
			headers = {'Content-Type': 'application/json;charset=UTF-8'}
			result = requests.post(url,data=json.dumps(data), headers=headers)
			print("实时反欺诈接口返回值: " + str(result.content))
			return str(result.content)
		except Exception as error:
			print(url + " : Trager realtime interface failed! ")
			print("实时反欺诈接口返回值: " + error)
			result = 'false'
			return result


if __name__ == '__main__':
	cacheurl = 'http://123.57.16.129:9195/cache/addCache/wk_quality_order'
	#cachedict = [{'id_number':'test_id_card_mall','order_time':'2018-06-14 9:15:24','order_id':'order_udissso_test','order_status':'9','product_total':'8900','first_payment':'3500','redbagvalue':'4400','rates':'60'}]

	cachedict = [{"ip": "10.10.10.11", "createtime": "2018-06-18 9:15:24", "mobile": "18211900309", "eventtype": "1", "eventstatus": "1"}, {"ip": "10.10.10.11", "createtime": "2018-06-18 9:15:24", "mobile": "18160023942", "eventtype": "1", "eventstatus": "1"}]

	requesturl = 'http://123.57.16.129:9580/audit'
	requestdict = [{"@type":"cn.com.bsfit.frms.obj.AuditObject","frms_order_id":"test123456789","frms_customer_id":"7","frms_user_id":"38474954","frms_id_no":"370782198705201130","frms_phone_no":"18911499260","frms_biz_code":"9F.LOGIN","frms_oper_time":1529486400001,"frms_relative_phone":"18911499260","frms_ip":"10.10.10.10","frms_finger_print":"8923794789329832","frms_fingerprint_manufacturer":"bangbang","frms_net_status":"wifi","frms_mac":"72-C9-4E-DE-7A-AA","frms_longitude":98.23,"frms_dimension":74.23,"frms_device_type":"android","frms_ip_prov":"0","frms_ip_city":"0","frms_gps_prov":"0","frms_gps_city":"0","frms_phone_prov":"010","frms_phone_city":"010","frms_regist_channel":"weixin","frms_imei":"124671456789024","frms_register_ip_prov":"1","frms_register_ip_city":"1","frms_register_ip":"172.16.2.198","frms_trans_vol":1234567,"frms_contact_address":"北京市朝阳区","frms_card_no":"6227000013120300192","frms_latest_login_fingerprint":"0","frms_weiyan_tag":"0"}]

	delurl = 'http://123.57.8.17:9195/deletekey'
	deldata = {
  "biz":"PAY.CREDIT",
  "key":"udid-111666-wu",
  "tag":"设备指纹"
}
	inf = Interface()
	#inf.inf_realtime(requesturl,requestdict)
	#inf.add_realtime_cache(cacheurl,cachedict)
	inf.del_realtime_cache(delurl,deldata)
